package com.lagou.servlet;

import com.lagou.bean.Class;
import com.lagou.service.ClassService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ClassServlet", value = "/ClassServlet")
public class ClassMainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.通过service层调用Dao方法获取班级信息
        ClassService classService = new ClassService();
        //2.获取到所有的班级信息
        List<Class> Class = classService.findClass();
        for (com.lagou.bean.Class aClass : Class) {
            int num = classService.studenrNub(aClass.getCid());
            aClass.setNum(num);
        }
        //将班级信息传入到session
        request.getSession().setAttribute("classes",Class);
        //跳转页面,显示所有的班级信息
        response.sendRedirect("class.jsp");

    }
}
